
//
//  BaseNavigationViewController.m
//  ERenYiPu
//
//  Created by mac on 16/4/27.
//  Copyright © 2016年 mac. All rights reserved.
//
#import "BaseNavigationViewController.h"
#import "WebViewController.h"
@implementation BaseNavigationViewController
+ (void)initialize
{
    // 1.设置导航栏主题
    [self setupNavTheme];
    
    // 1.设置导航栏按钮主题
    [self setupItemTheme];
}
+ (void)setupNavTheme
{   //初始化导航栏
    UINavigationBar*navBar=[UINavigationBar appearance];
    //设置背景图片
    [navBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
    //设置背景颜色
    navBar.barTintColor=[UIColor colorWithHexString:@"#292929"];
    navBar.translucent=NO;

    //设置字体属性(颜色,阴影,字体大小)
    [navBar setTitleTextAttributes:@{NSForegroundColorAttributeName:WhiteColor,NSFontAttributeName:[UIFont systemFontOfSize:20.0f]}];
    

    
}
+ (void)setupItemTheme{
    //创建item
    UIBarButtonItem * item= [UIBarButtonItem appearance];
    
    //item设置默认按钮(状态,字体大小,阴影)
    
    [item setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor],NSFontAttributeName:[UIFont systemFontOfSize:17]} forState:UIControlStateNormal];
    
    //设置点击颜色
    [item setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]} forState:UIControlStateHighlighted];
    
    //设置失效按钮颜色
    [item setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:0.3]} forState:UIControlStateDisabled];
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    // 清空手势识别器的代理, 就能恢复以前滑动移除控制器的功能
    self.interactivePopGestureRecognizer.delegate = nil;
    
}
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    if (self.viewControllers.count > 0) { // 如果push的不是根控制器(不是栈底控制器)
        viewController.hidesBottomBarWhenPushed = YES;
        
        // 左上角的返回
        UIButton *btn = [[UIButton alloc] init];
        
        //设置默认图像
        [btn setImage:[UIImage imageNamed:@"back1"] forState:UIControlStateNormal];
        //设置点击图像
        [btn sizeToFit];

        //设置点击事件
        NSLog(@"--++++%@", [viewController class]);
    
        if ([[viewController class] isSubclassOfClass:[WebViewController class]]) {
            
            WebViewController *webView = (WebViewController *)viewController;
            
//            if (webView.backType == 1000) {
//
//                [btn addTarget:self  action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
//
//            }else {
                [btn addTarget:self  action:@selector(back1) forControlEvents:UIControlEventTouchUpInside];
//            }
            
           
        }else {
            
            [btn addTarget:self  action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
        }
        
        
        //重新给个button
        viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
       
        
        
    } 
    [super pushViewController:viewController animated:animated];
}
- (void)back1
{
    
      [self popToRootViewControllerAnimated:YES];
}
- (void)back
{
    [self popViewControllerAnimated:YES];
}
@end
